var ObjectCard = Class.create({
	initialize : function(){
		this.conf;
		this.id;
		this.title;
		this.content;
		this.icon;
		this.width;
		this.height;
		this.parentId;
		this.className;
		this.onClick;
		this.active;
		this.suite;
		this.rank;
	},
	init : function(/*Object*/ o){
		this.conf = o;
		this.id = o.id;
		this.title = o.title;
		this.content = o.content;
		this.icon = o.icon;
		this.width = o.width?o.width:'30px';
		this.height = o.height?o.height:'60px';
		this.parentId = o.parentId;
		this.className = o.className;
		this.onClick = o.onClick;
		this.cardId = o.cardId;
		this.cardType = o.cardType;
		this.distance = o.distance;
		this.active = o.active;
		this.suite = o.suite;
		this.rank = o.rank;
	},
	setActive : function(active){
		this.active = active;
	},
	setClassName : function(className){
		this.className = className;
	},
	draw : function(){
		//var element = document.getElementById(this.id);
		var parent = document.getElementById(this.parentId);
		var element = document.createElement('DIV');
		element.style.width = this.width;
		element.style.height = this.height;
		//element.style.word-break = break-all;
		element.className = this.className;
		var divId = this.id;
		if(this.active){
			element.onclick = function() {player.cardClick(divId);};
			element.ondblclick = function() {player.cardDBClick(divId);};
		}
		//element.setAttribute("onclick", "main.cardClick('"+this.id+"')");
		if(this.content){
			//element.innerHTML = "<font size='-2'>"+this.content+"</font>";
			element.innerHTML = "<font size='-2'>"+this.content+"</font>";
		}
		else if(this.icon){
			element.innerHTML = this.icon;
		}
		element.setAttribute("id", this.id);
		element.setAttribute("w:cardType", this.cardType);
		parent.appendChild(element);
		var metaInfo = {};
		metaInfo["card_id"] = this.id;
		metaInfo["card_type"] = this.cardType;
		if(this.cardType == "arm"){
			ddManager.registerDDItem(this.id, [this.cardType], {}, metaInfo);
		}
		else{
			ddManager.registerDDItem(this.id, ["attack_"+this.distance], {}, metaInfo);
		}
		
	},
	drawCard : function(){
		var parent = document.getElementById(this.parentId);
		var element = document.createElement('DIV');
		element.style.width = this.width;
		element.style.height = this.height;
		//element.style.word-break = break-all;
		element.className = this.className;
		var divId = this.id;
		if(this.active){
			element.onclick = function() {player.cardClick(divId);};
			element.ondblclick = function() {player.cardDBClick(divId);};
		}
		//element.setAttribute("onclick", "main.cardClick('"+this.id+"')");
		if(this.suite){
			var suiteElement = document.createElement('DIV');
			suiteElement.innerHTML = "<img src='" + this.getSuiteIcon(this.suite); + "' >";
			element.appendChild(suiteElement);
			suiteElement.style.display = "inline-block";
		}
		if(this.rank){
			var rankElement = document.createElement('DIV');
			rankElement.innerHTML = "<img src='" + this.getRankIcon(this.rank); + "' >";
			element.appendChild(rankElement);
			rankElement.style.display = "inline-block";
		}
		if(this.content){
			var contentElement = document.createElement('DIV');
			contentElement.innerHTML = "<font size='-2'>"+this.content+"</font>";
			element.appendChild(contentElement);
		}
		else if(this.icon){
			element.innerHTML = this.icon;
		}
		element.setAttribute("id", this.id);
		element.setAttribute("w:cardType", this.cardType);
		parent.appendChild(element);
		var metaInfo = {};
		metaInfo["card_id"] = this.id;
		metaInfo["card_type"] = this.cardType;
		if(this.cardType == "arm"){
			ddManager.registerDDItem(this.id, [this.cardType], {}, metaInfo);
		}
		else{
			ddManager.registerDDItem(this.id, ["attack_"+this.distance], {}, metaInfo);
		}
	},
	drawUsedCard : function(){
		//var element = document.getElementById(this.id);
		var parent = document.getElementById(this.parentId);
		var element = document.createElement('DIV');
		element.style.width = this.width;
		element.style.height = this.height;
		//element.style.word-break = break-all;
		element.className = this.className;
		var divId = this.id;
		element.onclick = function() {player.cardClick(divId);};
		element.ondblclick = function() {player.cardDBClick(divId);};
		
		//element.setAttribute("onclick", "main.cardClick('"+this.id+"')");
		if(this.content){
			//element.innerHTML = "<font size='-2'>"+this.content+"</font>";
			element.innerHTML = "<font size='-2'>"+this.content+"</font>";
		}
		else if(this.icon){
			element.innerHTML = this.icon;
		}
		element.setAttribute("id", this.id);
		element.setAttribute("w:cardType", this.cardType);
		parent.appendChild(element);
		var metaInfo = {};
		metaInfo["card_id"] = this.id;
		metaInfo["card_type"] = this.cardType;
		if(this.cardType == "arm"){
			ddManager.registerDDItem(this.id, [this.cardType], {}, metaInfo);
		}
		else{
			ddManager.registerDDItem(this.id, ["attack_"+this.distance], {}, metaInfo);
		}
		
	},
	drawFront : function(){
		var parent = document.getElementById(this.parentId);
		var element = document.createElement('DIV');
		element.style.width = '25px';
		element.style.height = '40px';
		//element.style.word-break = break-all;
		if(this.className){
			element.className = this.className;
		}
		else{
			element.className = 'cardDisableClass';
		}
		var divId = this.id;
		element.setAttribute("id", this.id);
		element.setAttribute("w:cardType", this.cardType);
		element.onclick = function() {player.cardClick(divId);};
		element.ondblclick = function() {player.cardDBClick(divId);};
		//element.setAttribute("onclick", "main.cardClick('"+this.id+"')");
		if(this.content){
			element.innerHTML = "<font size='-3'>"+this.content+"</font>";
//			element.innerHTML = this.content;
		}
		else if(this.icon){
			element.innerHTML = this.icon;
		}
		parent.appendChild(element);
	},
	drawBack : function(){
		var parent = document.getElementById(this.parentId);
		var element = document.createElement('DIV');
		element.style.width = this.width;
		element.style.height = this.height;
		element.className = 'cardBackClass';
		var divId = this.id;
		element.setAttribute("id", this.id);
		element.setAttribute("w:cardType", this.cardType);
		//element.onclick = function() {player.cardClick(divId);};
		//element.setAttribute("onclick", "main.cardClick('"+this.id+"')");
		if(this.content){
			//element.innerHTML = "<font size='-2'>"+this.content+"</font>";
			element.innerHTML = this.content;
		}
		else if(this.icon){
			element.innerHTML = this.icon;
		}
		parent.appendChild(element);
		
	},
	resetCardDraw : function(divId){
		//var element = document.getElementById(this.id);
		var element = document.getElementById(divId);
		element.style.width = this.width;
		element.style.height = this.height;
		element.className = this.className;
		//var divId = this.id;
		//element.onclick = function() {player.cardClick(divId);};
		//element.setAttribute("onclick", "main.cardClick('"+this.id+"')");
		if(this.content){
			element.innerHTML = "<font size='-2'>"+this.content+"</font>";
		}
		else if(this.icon){
			element.innerHTML = this.icon;
		}
		//element.setAttribute("id", this.id);
		element.setAttribute("w:cardType", this.cardType);
		//parent.appendChild(element);

	},
	removeCardDraw : function(divId){
		var element = document.getElementById(divId);
		element.style.width = this.width;
		element.style.height = this.height;
		element.className = "";
		element.innerHTML = "";
	},
	cardClick : function(id){
		var element = document.getElementById(this.id);
		element.style.border = 'border : dotted 2px #0000ff;';
	},
	getSuiteIcon : function(suite){
		var icon = "";
		if(suite == "suite.spade"){
			icon = "../img/suite_spade.png";
		}
		else if(suite == "suite.heart"){
			icon = "../img/suite_heart.png";
		}
		else if(suite == "suite.club"){
			icon = "../img/suite_club.png";
		}
		else if(suite == "suite.diamond"){
			icon = "../img/suite_diamond.png";
		}
		return icon;
	},
	getRankIcon : function(rank){
		var icon = "";
		if(rank == "A"){
			icon = "../img/rank_A.png";
		}
		else if(rank == "2"){
			icon = "../img/rank_2.png";
		}
		else if(rank == "3"){
			icon = "../img/rank_3.png";
		}
		else if(rank == "4"){
			icon = "../img/rank_4.png";
		}
		else if(rank == "5"){
			icon = "../img/rank_5.png";
		}
		else if(rank == "6"){
			icon = "../img/rank_6.png";
		}
		else if(rank == "7"){
			icon = "../img/rank_7.png";
		}
		else if(rank == "8"){
			icon = "../img/rank_8.png";
		}
		else if(rank == "9"){
			icon = "../img/rank_9.png";
		}
		else if(rank == "10"){
			icon = "../img/rank_10.png";
		}
		else if(rank == "J"){
			icon = "../img/rank_J.png";
		}
		else if(rank == "Q"){
			icon = "../img/rank_Q.png";
		}
		else if(rank == "K"){
			icon = "../img/rank_K.png";
		}
		return icon;
	}
	
});
